package com.rui.study.commons.study.http;

import com.rui.study.commons.model.Result;
import com.rui.study.commons.model.StatusCode;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class GoodsConcurrentRequest extends AbstractConcurrentRequest {

    public static final String NOT_GETTING_GOODS_THREADS = "NOT.GETTING.GOODS.THREADS";

    public GoodsConcurrentRequest() {
    }

    public GoodsConcurrentRequest(int threadCount) {
        super(threadCount);
    }

    public GoodsConcurrentRequest(RestTemplate restTemplate, int threadCount) {
        super(restTemplate, threadCount);
    }

    @Override
    protected RequestEntity buildRequestEntity() {
        return null;
    }

    @Override
    protected void processAggregationResult(ResponseEntity<?> result, String threadName, AggregationResult aggregationResult) {
        Object obj = result.getBody();
        if (obj instanceof Result) {
            Result res = (Result) obj;
            if (StatusCode.SUCCEED.getStatus() != res.getStatus())
                processListResult(NOT_GETTING_GOODS_THREADS, threadName, aggregationResult);
                super.processAggregationResult(result, threadName, aggregationResult);
        }
    }
}
